home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / asywiz / asmwiz.doc < prev    next >
Encoding:
Text File  |  1994-11-03  |  44.0 KB  |  1,196 lines

  1.                 The Assembly Wizard's Library            page 1
  2.                           Version 2.0
  3.  
  4.      AsmWiz  Copyright (c) 1990-1994  Thomas G. Hanlin III
  5.  
  6.  
  7.  
  8. This is AsmWiz, a library of assembly language routines for
  9. assembly language programmers. It is copyrighted and may be
  10. distributed only under the following conditions:
  11.  
  12.    All AsmWiz files must be distributed together as a unit in
  13.    unmodified form. No files may be left out or added.
  14.  
  15. YOU USE THIS LIBRARY AT YOUR OWN RISK. I have tested it on my
  16. own computer, but I will not assume responsibility for any
  17. problems which AsmWiz may cause you.
  18.  
  19. It is expected that if you find AsmWiz useful, you will register
  20. your copy. You may not use AsmWiz routines in programs intended
  21. for distribution unless you have registered.
  22.  
  23. Registration gets you the latest version of AsmWiz, complete
  24. with full source code. The source code is designed for the MASM
  25. 6.0 and may require modifications to work with other assemblers.
  26.  
  27. The AsmWiz library was designed for use with small assembly
  28. programs and is compatible with the creation of COM files. All
  29. CALLs are of the NEAR variety. A FAR model will be created if
  30. there is sufficient interest.
  31.  
  32. For an example of how to set up your program to access the
  33. AsmWiz library, how to LINK the routines, and so forth, see the
  34. EXAMPLE.ASM, EXAMPLE.COM, and ?CREATE.BAT files. The file
  35. PACKING.LST tells you which ?CREATE batch file to use with which
  36. assembler. There are versions for A86, MASM, OPTASM, QuickASM,
  37. and TASM.
  38.  
  39. Note that DOS-dependent services expect DOS 2.0 or higher
  40. versions unless otherwise specified.
  41.  
  42.                        Table of Contents                 page 2
  43.  
  44.  
  45.  
  46.  Overview and Legal Info ................................... 1
  47.  
  48.  Base Conversions .......................................... 3
  49.  
  50.  Exception Handling ........................................ 4
  51.  
  52.  Delays and Countdowns ..................................... 5
  53.  
  54.  File Handling ............................................. 6
  55.  
  56.  Filename Manipulation ..................................... 8
  57.  
  58.  Keyboard Services ......................................... 9
  59.  
  60.  Long Integer Math ........................................ 10
  61.  
  62.  Memory Services .......................................... 11
  63.  
  64.  Mouse Services ........................................... 12
  65.  
  66.  Sound and Music .......................................... 13
  67.  
  68.  String Services .......................................... 14
  69.  
  70.  Telecommunications ....................................... 16
  71.  
  72.  Time and Date ............................................ 17
  73.  
  74.  Video Services ........................................... 18
  75.  
  76.  Miscellaneous Services ................................... 27
  77.  
  78.  Error Codes .............................................. 28
  79.  
  80.                        Base Conversions                  page 3
  81.  
  82.  
  83.  
  84. The Base Conversion Services provide the ability to convert back
  85. and forth between a number and its ASCIIZ representation. Any
  86. base from 2-36 may be employed, so these routines encompass
  87. binary, decimal, hex and octal conversions. Services are
  88. provided for integers and long integers, both signed and
  89. unsigned.
  90.  
  91.  
  92. The following services are available:
  93.  
  94.    BC_ASC2INT    convert ASCIIZ string to unsigned integer
  95.                        BL <-- base from which to convert
  96.                     DS:SI <-- ptr to string
  97.                     -------
  98.                        AX = unsigned integer
  99.  
  100.    BC_ASC2LONG   convert ASCIIZ string to unsigned long int
  101.                        BL <-- base from which to convert
  102.                     DS:SI <-- ptr to string
  103.                     -------
  104.                     DX,AX = unsigned long integer
  105.  
  106.    BC_ASC2SINT   convert ASCIIZ string to signed integer
  107.                        BL <-- base from which to convert
  108.                     DS:SI <-- ptr to string
  109.                     -------
  110.                        AX = signed integer
  111.  
  112.    BC_ASC2SLONG  convert ASCIIZ string to signed long integer
  113.                        BL <-- base from which to convert
  114.                     DS:SI <-- ptr to string
  115.                     -------
  116.                     DX,AX = signed long integer
  117.  
  118.    BC_INT2ASC    convert unsigned integer to ASCIIZ string
  119.                        AX <-- unsigned integer
  120.                        BL <-- base to which to convert
  121.                     ES:DI <-- ptr to string buffer (17 bytes)
  122.  
  123.    BC_LONG2ASC   convert unsigned long int to ASCIIZ string
  124.                     DX,AX <-- unsigned long integer
  125.                        BL <-- base to which to convert
  126.                     ES:DI <-- ptr to string buffer (33 bytes)
  127.  
  128.    BC_SINT2ASC   convert signed integer to ASCIIZ string
  129.                        AX <-- signed integer
  130.                        BL <-- base to which to convert
  131.                     ES:DI <-- ptr to string buffer (18 bytes)
  132.  
  133.    BC_SLONG2ASC  convert signed long integer to ASCIIZ string
  134.                     DX,AX <-- signed long integer
  135.                        BL <-- base to which to convert
  136.                     ES:DI <-- ptr to string buffer (34 bytes)
  137.  
  138.                       Exception Handling                 page 4
  139.  
  140.  
  141.  
  142. The Exception Handling Services allow your program to take
  143. control over exception conditions. This covers critical errors
  144. and Control-Break / Control-C handling.
  145.  
  146. The critical error handler gives you the ability to recover from
  147. critical errors, which would otherwise cause the infamous
  148. "R>etry, I>gnore, F>ail, A>bort?" prompt.
  149.  
  150. The break handler allows your program to ignore the Control-C
  151. and Control-Break keys or to process them in an orderly manner.
  152. This is vital if you are using any of the AsmWiz services which
  153. need to be shut down before the program terminates. Up to eight
  154. procedures can be called when ^Break or ^C are used (they will
  155. be ignored if you turn off ^Break / ^C).
  156.  
  157.  
  158. The following services are available:
  159.  
  160.  
  161.    EH_INITCRIT   initialize the critical error handler
  162.  
  163.    EH_CRITERR    check for a critical error
  164.  
  165.    EH_CRITDONE   terminates the critical error handler
  166.  
  167.    EH_INITBREAK  initialize the ^C / ^Break handler
  168.  
  169.    EH_ADDBREAK   add a procedure to be called on ^C / ^Break
  170.                        DX <-- procedure offset (CS-relative)
  171.  
  172.    EH_SETBREAK   allow or ignore ^C and ^Break
  173.                        AL <-- 0 to ignore, 1 to allow
  174.  
  175.    EH_SUBBREAK   remove a procedure to be called on ^C / ^Break
  176.                        DX <-- procedure offset (CS-relative)
  177.  
  178.                      Delays and Countdowns               page 5
  179.  
  180.  
  181.  
  182. The Delay Services are for those times when you want the
  183. computer to sit around doing nothing for a while. Delays of
  184. various timing resolution are available for anything from small
  185. to large waits.
  186.  
  187. Notes on the 100th-second delay and countdown services:
  188.  
  189. Since MD_DONE must be called before the program terminates, you
  190. should use the EH_ADDBREAK service to insure that MD_DONE is
  191. called if Control-Break or Control-C are permitted to abort the
  192. program.
  193.  
  194. Timers 0-1 may be used by AsmWiz itself for various services.
  195.  
  196. See ASMWIZ.MAN for more details on the 100th-second delay
  197. services.
  198.  
  199.  
  200. The following services are available:
  201.  
  202.  
  203.    MD_DELAY      delay for a number of 100ths of seconds
  204.                        CX <-- delay (0-32767)
  205.  
  206.    MD_DONE       terminate 100th-second delay handler
  207.  
  208.    MD_GETTIMER   get a delay count
  209.                        AL <-- timer number (0-7)
  210.                     -------
  211.                        CX = delay * 2 (0-65534)
  212.  
  213.    MD_INIT       initialize 100th-second delay handler
  214.  
  215.    MD_SETTIMER   set a delay count
  216.                        AL <-- timer number (0-7)
  217.                        CX <-- delay (0-32767)
  218.  
  219.    MD_TICK       delay for a number of clock ticks (18ths of seconds)
  220.                        CX <-- delay (0-65535)
  221.  
  222.                         File Handling                    page 6
  223.  
  224.  
  225.  
  226. The File Handling Services provide a comprehensive and powerful
  227. set of routines for file handling. The usual open file,
  228. read/write, file pointer manipulation, and close file operations
  229. are supported, of course. New conveniences include automatic
  230. network support (file sharing is used if the DOS version is high
  231. enough), optional input buffering for extra speed, and special
  232. support for text files. Critical error handling is supported via
  233. the Exception Handling Services.
  234.  
  235. These services return with the carry flag set if there is an
  236. error. In that case, the AX register returns the error code.
  237. Note that, unlike most other services, the file services are
  238. allowed to change the AX register regardless of whether an error
  239. occurred.
  240.  
  241.  
  242. The following services are available:
  243.  
  244.    DF_CLOSE      close a file
  245.                        BX <-- (virtual) file handle
  246.  
  247.    DF_DONE       terminate the File Handling Services
  248.                  (closes all open files)
  249.  
  250.    DF_FLUSH      flush a file to disk (updates disk directory)
  251.                        BX <-- (virtual) file handle
  252.  
  253.    DF_GETTIME    get file time/date stamp
  254.                        BX <-- (virtual) file handle
  255.                     -------
  256.                        AX = time
  257.                        DX = date
  258.  
  259.    DF_HANDLE     get DOS file handle given virtual file handle
  260.                        BX <-- (virtual) file handle
  261.                     -------
  262.                        BX = (DOS) file handle
  263.  
  264.    DF_INIT       initialize the File Handling Services
  265.                        DX <-- 0
  266.  
  267.    DF_LOCATE     set file read/write pointer
  268.                        BX <-- (virtual) file handle
  269.                        CL <-- 0 for offset from start
  270.                               1 for offset from current posn
  271.                               2 for offset from end of file
  272.                     DX,AX <-- offset
  273.  
  274.                         File Handling                    page 7
  275.  
  276.  
  277.  
  278.    DF_OPEN       open a file for access
  279.                        AX <-- set bit 0 for read
  280.                                   bit 1 for write
  281.                                   bit 2 for create
  282.                                   bit 3 for text file
  283.                                   bits 4-15 zero
  284.                     DS:DX <-- pointer to ASCIIZ filename
  285.                        CX <-- length of input buffer (0: none)
  286.                     ES:SI <-- pointer to input buffer, if any
  287.                     -------
  288.                        BX = (virtual) file handle
  289.  
  290.    DF_READ       read from a file
  291.                        BX <-- (virtual) file handle
  292.                        CX <-- bytes to read
  293.                               (for text files, is max bytes)
  294.                     DS:DX <-- pointer to read buffer
  295.                     -------
  296.                        AX = bytes actually read
  297.                             (if NC and not text mode)
  298.  
  299.    DF_TIME       set file time/date stamp
  300.                        BX <-- (virtual) file handle
  301.                        AX <-- time
  302.                        DX <-- date
  303.  
  304.    DF_WHERE      get file read/write pointer
  305.                        BX <-- (virtual) file handle
  306.                     -------
  307.                     DX,AX = offset
  308.  
  309.    DF_WRITE      write to a file
  310.                        BX <-- (virtual) file handle
  311.                        CX <-- bytes to write
  312.                               (for text files, is ignored)
  313.                     DS:DX <-- pointer to write buffer
  314.  
  315.                     Filename Manipulation                page 8
  316.  
  317.  
  318.  
  319. The Filename Manipulation Services allow various operations on
  320. filenames which make it possible to duplicate the capabilities
  321. of the DOS command shell. This includes finding a file which
  322. matches a specified pattern, forcing a filename to match a given
  323. pattern, splitting a filespec into its component parts, and
  324. completing a (possibly partial) filespec.
  325.  
  326.  
  327. The following services are available:
  328.  
  329.    FI_COMPLETE   complete a filespec from a partial spec
  330.                     DS:SI <-- filename (may have drive,
  331.                                  dir, "." or "..", etc)
  332.                     DS:BX <-- default extension to be added
  333.                                  (without ".")
  334.                     ES:DI <-- 80-byte buffer for result
  335.                     -------
  336.                     Flags = CY if the filespec is not valid
  337.                             NC if it went ok
  338.  
  339.    FI_MATCH      see if a filename matches a specified pattern
  340.                     DS:SI <-- pattern (may contain wildcards)
  341.                     ES:DI <-- filename (may not contain drive
  342.                                  or path specs)
  343.                     -------
  344.                     Flags = ZF if the filename matches
  345.                             NZ if the filename doesn't match
  346.  
  347.    FI_PATTERN    push a filename through a pattern spec
  348.                     DS:SI <-- filename (no drive or
  349.                                  directory allowed)
  350.                     DS:BX <-- pattern
  351.                     ES:DI <-- 13-byte buffer for results
  352.                     -------
  353.                     Flags = CY for some filename/pattern errors
  354.                             NC if it went ok
  355.  
  356.    FI_SPLIT      split a path specification into drive,
  357.                  directory, filename
  358.                     DS:SI <-- path spec
  359.                     ES:DI <-- 80-byte buffer for results
  360.  
  361.                        Keyboard Services                 page 9
  362.  
  363.  
  364.  
  365. The Keyboard Services provide access to the keyboard. They let
  366. you get and set the Caps Lock and Num Lock states, or get a key
  367. in a variety of ways. Both DOS and BIOS keyboard access is
  368. provided, so support for input redirection is optional.
  369.  
  370. Microsoft and IBM seemed to find it curiously difficult to
  371. provide a simple set of keyboard functions. These routines hide
  372. most of the quirks from you. However, there are still things to
  373. keep in mind. There is no BIOS or DOS support for setting Caps
  374. Lock or Num Lock, so it is done directly. This means that the
  375. keyboard status lights for these keys may be incorrect on older
  376. machines if you set the key states from your program. DOS does
  377. not usually support "enhanced" keyboards (101-key or more), so
  378. if you need to access enhanced keys (like F11 and F12), you
  379. can't use the DOS services or support input redirection. With
  380. the BIOS services, you must choose between compatibility (old
  381. keyboard handling, ignores F11, F12, etc if present) and full
  382. enhanced mode support (doesn't work on older machines).
  383.  
  384. The prefix for the keyboard routine is based on the way keyboard
  385. access is done:
  386.  
  387.    MK_    machine-level keyboard access (direct to hardware)
  388.    BKO_   old BIOS keyboard access (compatible with everything)
  389.    BK_    new BIOS keyboard access (only for "enhanced" kbd)
  390.    DK_    DOS keyboard access (supports input redirection)
  391.  
  392.  
  393. Background info aside, these routines are really quite simple:
  394.  
  395.    BKO_GETKEY    get a key from the keyboard (bit flags: set
  396.    BK_GETKEY      bit 0 to wait for key, 1 to screen extended
  397.    DK_GETKEY      keys, 2 to capitalize, 3 to clear kbd buffer)
  398.                          AL <-- bit flags
  399.                     -------
  400.                          AX = key (- ext'ded., 0 none, + ASCII)
  401.                          Flags = NZ if got a key, ZF if no key
  402.  
  403.    BKO_GETCAPS   get state of Caps Lock (compatible)
  404.    BK_GETCAPS    get state of Caps Lock (enhanced kbd only)
  405.                     -------
  406.                          AX = 0 if off, 0FFFFh if on
  407.  
  408.    BKO_GETNUM    get state of Num Lock (compatible)
  409.    BK_GETNUM     get state of Num Lock (enhanced kbd only)
  410.                     -------
  411.                          AX = 0 if off, 0FFFFh if on
  412.  
  413.    MK_SETCAPS    set state of Caps Lock
  414.                          AX <-- 0 to turn off, non-0 to turn on
  415.  
  416.    MK_SETNUM     set state of Num Lock
  417.                          AX <-- 0 to turn off, non-0 to turn on
  418.  
  419.                        Long Integer Math                page 10
  420.  
  421.  
  422.  
  423. The Long Integer Math Services provide support for the basic
  424. arithmetic operations on unsigned long integers. They allow you
  425. to add two 32-bit integers, subtract one 32-bit integer from
  426. another, multiply two 32-bit integers (giving a 64-bit result),
  427. and divide a 63-bit integer by a 32-bit integer (giving a 32-bit
  428. result and 32-bit remainder).
  429.  
  430. Since 32-bit integers are rather unwieldy unless you're using an
  431. 80386 or above (in which case you don't need these services
  432. anyway), the numbers are passed back and forth through a buffer
  433. in memory.
  434.  
  435.  
  436. The following services are available:
  437.  
  438.    MA_ADD32      add two unsigned long integers
  439.                     DS:SI   <-- first operand
  440.                     DS:SI+4 <-- second operand
  441.                     -------
  442.                     DS:SI+8 = result
  443.  
  444.    MA_DIV32      divide an unsigned 63-bit integer by an
  445.                  unsigned long integer
  446.                     DS:SI   <-- dividend (64 bits: high bit=0)
  447.                     DS:SI+8 <-- divisor (unsigned long int)
  448.                     -------
  449.                     DS:SI+12 = quotient (unsigned long int)
  450.                     DS:SI+16 = remainder (unsigned long int)
  451.  
  452.    MA_MUL32      multiply two unsigned long integers
  453.                     DS:SI   <-- first operand
  454.                     DS:SI+4 <-- second operand
  455.                     -------
  456.                     DS:SI+8 = result (unsigned very long
  457.                                  integer: 64 bits)
  458.  
  459.    MA_SUB32      subtract one unsigned long int from another
  460.                     DS:SI   <-- first operand
  461.                     DS:SI+4 <-- second operand
  462.                     -------
  463.                     DS:SI+8 = result
  464.  
  465.                         Memory Services                 page 11
  466.  
  467.  
  468.  
  469. The Memory Services provide low-level routines for memory
  470. manipulation. They allow you to manipulate addresses, provide a
  471. "smart" block move service that automatically handles overlaps
  472. between source and destination areas, and allows you to save or
  473. restore blocks of memory in BASIC's BSAVE format.
  474.  
  475. Among the address manipulation services are routines to convert
  476. an address to have the smallest possible segment and highest
  477. possible offset (or vice versa) to allow REP operations to
  478. always handle up to 65,519 bytes without wrapping within the
  479. segment. This can also be useful in file operations.
  480.  
  481.  
  482. The following services are available:
  483.  
  484.    ME_BINFO      get information about a BSAVE-format file
  485.                     DS:DX <-- pointer to ASCIIZ filename
  486.                     -------
  487.                     ES:SI = segment:offset
  488.                        CX = image size (bytes)
  489.                     Flags = CY if unable to load file
  490.                             if CY, AX is error code
  491.  
  492.    ME_BLOAD      load a BSAVE-format file into memory
  493.                     DS:DX <-- pointer to ASCIIZ filename
  494.                     -------
  495.                     Flags = CY if unable to load file
  496.                             if CY, AX is error code
  497.  
  498.    ME_BSAVE      save a block of memory to a BSAVE-format file
  499.                     DS:DX <-- pointer to ASCIIZ filename
  500.                     ES:SI = segment:offset
  501.                        CX = image size (bytes)
  502.                     -------
  503.                     Flags = CY if unable to save memory
  504.                             if CY, AX is error code
  505.  
  506.    ME_HIGHOFS    convert an address to have the lowest segment
  507.                  & highest offset
  508.                     DX:AX <-- segment:offset
  509.                     -------
  510.                     DX:AX = converted segment:offset
  511.  
  512.    ME_LOWOFS     convert an address to have the highest segment
  513.                  & lowest offset
  514.                     DX:AX <-- segment:offset
  515.                     -------
  516.                     DX:AX = converted segment:offset
  517.  
  518.    ME_MOVE       move a block of memory w/o overlap conflicts
  519.                     DS:SI <-- source segment:offset
  520.                     ES:DI <-- destination segment:offset
  521.                        CX <-- bytes to move (0 - 65,519)
  522.  
  523.                         Mouse Services                  page 12
  524.  
  525.  
  526.  
  527. The Mouse Services provide a simple set of functions for dealing
  528. with Microsoft-compatible mouse devices. You may see if a mouse
  529. exists, control the mouse cursor, and get information about the
  530. mouse buttons.
  531.  
  532.  
  533. The following services are available:
  534.  
  535.    MO_GLOCATE    set the mouse cursor location (graphics)
  536.                        CX = X coordinate (0-MaxX)
  537.                        DX = Y coordinate (0-MaxY)
  538.  
  539.    MO_GWHERE     get the mouse cursor location & button states
  540.                        AL = left button (1: pressed, 0: not)
  541.                        AH = right button (1: pressed, 0: not)
  542.                        CX = X coordinate (0-MaxX)
  543.                        DX = Y coordinate (0-MaxY)
  544.  
  545.    MO_HIDECURSOR hide the mouse cursor
  546.  
  547.    MO_INIT       see if a mouse is installed
  548.                     -------
  549.                        AL = number of mouse buttons
  550.                             (0 if no mouse)
  551.  
  552.    MO_LOCATE     set the mouse cursor location (text)
  553.                        DH <-- row (1-25)
  554.                        DL <-- column (1-80)
  555.  
  556.    MO_RANGE      set the mouse cursor range (text)
  557.                        CH <-- top row (1-25)
  558.                        CL <-- leftmost column (1-80)
  559.                        DH <-- bottom row (1-25)
  560.                        DL <-- rightmost column (1-80)
  561.  
  562.    MO_SHOWCURSOR show the mouse cursor
  563.  
  564.    MO_WHERE      get the mouse cursor location & button states
  565.                     -------
  566.                        AL = left button (1: pressed, 0: not)
  567.                        AH = right button (1: pressed, 0: not)
  568.                        DH = row (1-25)
  569.                        DL = column (1-80)
  570.  
  571.                         Sound and Music                 page 13
  572.  
  573.  
  574.  
  575. The Sound and Music Services provide the ability to generate
  576. sound effects and music. The current service is rather on the
  577. primitive side. It will be supplemented by a background
  578. (interrupt-driven) music command language in a future version of
  579. AsmWiz.
  580.  
  581.  
  582. The following services are available:
  583.  
  584.    MU_SOUND      produce a sound of a specified duration
  585.                  and frequency
  586.                     AX <-- frequency (Hertz or cycles/second:
  587.                               about 50-4000 is useful)
  588.                     DX <-- duration  (18ths of seconds)
  589.  
  590.                    String Services (ASCIIZ)             page 14
  591.  
  592.  
  593.  
  594. The ASCIIZ String Services provide an assortment of services for
  595. dealing with NUL-terminated strings.
  596.  
  597. Note that, although many of the string services are designed to
  598. place the result of processing a first string into a second
  599. string, it is not actually necessary to use two string buffers.
  600. The services are designed so that you can place the results back
  601. into the original string buffer by using the same address for
  602. both strings.
  603.  
  604.  
  605. The following routines are included amongst the ASCIIZ String
  606. Services:
  607.  
  608.    S0_COMPARE    compare two strings
  609.                     DS:SI <-- first string
  610.                     ES:DI <-- second string
  611.                     -------
  612.                     Flags = ZF if equal, NZ if not equal
  613.                             CY if first < second
  614.                             NC if first >= second
  615.  
  616.    S0_DUPE       form a string by duplicating a character
  617.                     ES:DI <-- result string
  618.                        AL <-- character to duplicate
  619.                        CX <-- number of times to repeat
  620.  
  621.    S0_FIND       search for a substring within a string
  622.                     DS:SI <-- substring
  623.                     ES:DI <-- string
  624.                     -------
  625.                        AX = position of substring in string
  626.                          (0 if not found; ZF set accordingly)
  627.  
  628.    S0_LEFT       copy a specified section from the left of
  629.                  a string
  630.                     DS:SI <-- source string
  631.                        CX <-- number of characters to copy
  632.                     ES:DI <-- result string
  633.  
  634.    S0_LENGTH     get the length of a string (excluding the
  635.                  null terminator)
  636.                     DS:SI <-- string
  637.                     -------
  638.                        CX = string length
  639.  
  640.    S0_LOCASE     convert a string to lowercase (international)
  641.                     DS:SI <-- source string
  642.                     ES:DI <-- result string
  643.  
  644.    S0_LOCASES    convert a string to lowercase (American)
  645.                     DS:SI <-- source string
  646.                     ES:DI <-- result string
  647.  
  648.                    String Services (ASCIIZ)             page 15
  649.  
  650.  
  651.  
  652.    S0_MID        copy a specified section of a string
  653.                     DS:SI <-- source string
  654.                        DX <-- where to start copying from (1-xx)
  655.                        CX <-- how many characters to copy
  656.                     ES:DI <-- result string
  657.  
  658.    S0_RIGHT      copy a specified section from the right side
  659.                  of a string
  660.                     DS:SI <-- source string
  661.                        CX <-- number of characters to copy
  662.                     ES:DI <-- result string
  663.  
  664.    S0_TRIM       trim the "white space" (blanks and control
  665.                  codes) from either or both sides of a string
  666.                     DS:SI <-- source string
  667.                        AL <-- set bit 0 to trim the left
  668.                                   bit 1 to trim the right
  669.                     ES:DI <-- result string
  670.  
  671.    S0_UPCASE     convert a string to uppercase (international)
  672.                     DS:SI <-- source string
  673.                     ES:DI <-- result string
  674.  
  675.    S0_UPCASES    convert a string to uppercase (American)
  676.                     DS:SI <-- source string
  677.                     ES:DI <-- result string
  678.  
  679.                       Telecommunications                page 16
  680.  
  681.  
  682.  
  683. The Telecommunications Services provide functions that are
  684. useful for telecommunications. At the moment, this is limited to
  685. services that aid in performing file transfers and similar
  686. functions.
  687.  
  688.  
  689. The following routines are included amongst the
  690. Telecommunications Services:
  691.  
  692.    TC_CHKSUM     calculate the checksum for a block of data
  693.                     DS:SI <-- pointer to a data block
  694.                        CX <-- length of data block (in bytes)
  695.                     -------
  696.                        AX = checksum
  697.  
  698.    TC_CRC        calculate the 16-bit CRC of a block of data
  699.                     DS:SI <-- pointer to a data block
  700.                        CX <-- length of data block (in bytes)
  701.                     -------
  702.                        AX = resulting CRC
  703.  
  704.                     Time and Date Services              page 17
  705.  
  706.  
  707.  
  708. The Time and Date Services provide international time and date
  709. handling. Based on the country code given it by DOS, these
  710. services return strings that represent the current time or date
  711. in the appropriate format for that country.
  712.  
  713. These services provide a simple way to make your software work
  714. properly on any computer anywhere, across the world.
  715.  
  716. See the COUNTRY entry under CONFIG.SYS in your DOS manual for
  717. more details. Note that DOS version 3.0 or greater is required
  718. to ensure that the date and time delimiters are appropriate.
  719. Otherwise, the date and time formats will still be correct, but
  720. the delimiters used will be assumed to be "-" for the date and
  721. ":" for the time. With DOS versions before 3.0, the time will be
  722. presented in 12-hour (am/pm) format.
  723.  
  724.  
  725. The following routines are included amongst the Time and Date
  726. Services:
  727.  
  728.    TD_GETDATE    get the current date as an ASCIIZ string
  729.                  DS:DX <-- pointer to a buffer (11 bytes)
  730.                     AL <-- 0 for 2-digit year
  731.                            1 for 4-digit year
  732.  
  733.    TD_GETTIME    get the current time as an ASCIIZ string
  734.                  DS:DX <-- pointer to a buffer (8 bytes)
  735.  
  736.                         Video Services                  page 18
  737.  
  738.  
  739.  
  740. Displaying text is something that almost every program will do.
  741. The AsmWiz library contains numerous sets of video services
  742. which make it easy to use the display in a consistent manner.
  743.  
  744. The display services are divided into five sets of routines,
  745. each of which provides similar capabilities:
  746.  
  747.    DV    DOS-level services
  748.    BV    BIOS-level services
  749.    MV    Machine-level services for text modes
  750.    CG    Machine-level services for CGA graphics modes
  751.    HG    Machine-level services for Hercules graphics mode
  752.  
  753. The DOS services provide the maximum level of compatibility.
  754. They are also the slowest of the video services and the least
  755. flexible. The main practical advantage of using DOS services is
  756. that they allow redirection, so the output of your program can
  757. be sent to a file, a printer, or a serial port as well as to the
  758. display. Since DOS itself has only minimal video support, you
  759. will need to make sure an ANSI driver is installed before using
  760. these services. See your DOS manual on ANSI.SYS for more
  761. information if you need it.
  762.  
  763. The BIOS services provide a very good level of compatibility.
  764. They are faster and more flexible than the DOS services. Like
  765. the DOS services, these routines are quite likely to work on
  766. nonstandard displays.
  767.  
  768. The machine-level services are the least compatible. They will
  769. work on any standard PC clone, but not on semi-compatible
  770. hardware or with nonstandard display devices. In return for this
  771. disadvantage, these services are much faster than the other
  772. services and provide a great deal more flexibility. Only the
  773. machine-level services support Hercules graphics mode.
  774.  
  775.                         Video Services                  page 19
  776.                      Text Display Speeds
  777.  
  778.  
  779.  
  780. Speed tests were conducted on an 8088 machine with a Phoenix
  781. BIOS, running MS-DOS 3.30. "Your mileage may differ". The tests
  782. were conducted on how quickly strings could be printed to the
  783. display.
  784.  
  785. Speeds are listed relative to the slowest display method (DOS
  786. services).
  787.  
  788.  
  789.  
  790.              +-----------+-----------+-----------+-----------+
  791.              | DV_STROUT | BV_STROUT | MV_STROUT | CG_STROUT |
  792. +------------+-----------+-----------+-----------+-----------+
  793. | Mode 3     |           |           |           |           |
  794. | text mode  |    100%   |    162%   |    572%   |    n/a    |
  795. +------------+-----------+-----------+-----------+-----------+
  796. | Mode 4     |           |           |           |           |
  797. | CGA lo-res |    100%   |    114%   |    n/a    |    180%   |
  798. +------------+-----------+-----------+-----------+-----------+
  799. | Mode 6     |           |           |           |           |
  800. | CGA hi-res |    100%   |    122%   |    n/a    |    204%   |
  801. +------------+-----------+-----------+-----------+-----------+
  802.  
  803.  
  804.  
  805. From this chart, you can see that using BIOS display services is
  806. 14% - 62% faster than using DOS services. Using machine-level
  807. services is 80% - 472% faster than using DOS services, and about
  808. 60% - 250% faster than using BIOS services.
  809.  
  810. If system compatibility is a major concern, then note that the
  811. DOS services are most compatible, followed by the BIOS services
  812. and then the machine-level services. The price you pay for
  813. compatibility is speed and flexibility. The machine-level
  814. services are the fastest and most flexible, followed by the BIOS
  815. services and then the DOS services.
  816.  
  817. It must be noted that almost all machines these days are 100%
  818. compatible and will run any of these routines with no problem.
  819.  
  820.                         Video Services                  page 20
  821.                    General Video Information
  822.           (not applicable to Hercules graphics mode)
  823.  
  824.  
  825.  
  826. For all text routines, color/attributes are encoded as a single
  827. byte value:
  828.  
  829. bit:    7   6   5   4   3   2   1   0
  830.       +---+---+---+---+---+---+---+---+
  831.       | B |  backgnd  | I |  foregnd  |
  832.       +---+---+---+---+---+---+---+---+
  833.  
  834. B:  "blink".  Set if the color is blinking.
  835.  
  836. I:  "intense".  Set if the foreground color is intense
  837.     (bright or light).
  838.  
  839. backgnd, foregnd:  the actual foreground and background
  840.    colors.  The bits specify the red, green, and blue
  841.    components of the color, giving the following color list:
  842.  
  843.        0    black     (if intense, usually displayed as gray)
  844.        1    blue
  845.        2    green
  846.        3    cyan
  847.        4    red
  848.        5    magenta
  849.        6    brown     (if intense, usually displayed as yellow)
  850.        7    white
  851.  
  852.  
  853. Text in CGA graphics modes is different. If you use BIOS or DOS
  854. services, you may only specify a foreground color, which may be
  855. 0-3. If you use the CGA machine-level services, you may specify
  856. a background color as well as a foreground color. Color encoding
  857. is the same as for text mode, with the exception that there are
  858. no "blinking" or "intense" bits, and the color range is 0-3
  859. instead of 0-7. The 0-3 range does not follow the above color
  860. list; instead, the colors depend on which CGA palette is in use.
  861.  
  862.                         Video Services                  page 21
  863.                    General Video Information
  864.  
  865.  
  866.  
  867. Screen modes are specified as a single byte, as follows:
  868.  
  869.      Mode  Resolu.  Type  Colr  Use      Adapter   Services
  870.  
  871.        0   40x25    b&w     16  text       CGA     MV, BV, DV
  872.        1   40x25    color   16  text       CGA     MV, BV, DV
  873.        2   80x25    b&w     16  text       CGA     MV, BV, DV
  874.  def-  3   80x25    color   16  text       CGA     MV, BV, DV
  875.        4   320x200  color    4  graphics   CGA     CG, BV, DV
  876.        5   320x200  b&w      4  graphics   CGA     CG, BV, DV
  877.        6   640x200  color    2  graphics   CGA     CG, BV, DV
  878.  mda-  7   80x25    b&w      -  text       MDA     BV
  879.       13   320x200  color   16  graphics   EGA     BV
  880.       14   640x200  color   16  graphics   EGA     BV
  881.       15   640x350  mono     -  graphics   EGA     BV
  882.       16   640x350  color   16  graphics   EGA     BV
  883.       17   640x480  color    2  graphics   VGA     BV
  884.       18   640x480  color   16  graphics   VGA     BV
  885.       19   320x200  color  256  graphics   VGA     BV
  886.  
  887. BV = BIOS video services
  888. DV = DOS video services
  889. MV = Machine-level text services
  890. CG = Machine-level CGA graphics services
  891.  
  892.                         Video Services                  page 22
  893.  
  894.  
  895.  
  896. All of the video services share a common nomenclature and
  897. calling procedure. For many of the services, you will have a
  898. choice of whether to use DOS, BIOS, Machine-level (text modes),
  899. Machine-level (CGA graphics modes), or Machine-level (Hercules
  900. graphics mode). The level is specified as a two-letter code
  901. prefix to the routine name, where the codes are as follows:
  902.  
  903.     DV    DOS Video
  904.     BV    BIOS Video
  905.     MV    Machine-level (text mode) Video
  906.     CG    Machine-level (CGA graphics mode) Video
  907.     HG    Machine-level (Hercules graphics mode) Video
  908.  
  909. For instance, the routine to display a string using DOS is
  910. called DV_STROUT (DOS Video service, String Output). Note that
  911. it usually isn't a good idea to "mix and match" video services
  912. of different types at the same time.
  913.  
  914.  
  915. The following services are available:
  916.  
  917.  
  918.     CHROUT      display a character
  919.                 BV,DV,MV,CG,HG
  920.                    AL <-- character
  921.  
  922.     CLS         clear the screen and home the cursor
  923.                 BV,DV,MV,CG,HG
  924.  
  925.     COLOR       set the text color
  926.                 BV,DV,MV,CG,HG
  927.                    AL <-- color/attribute
  928.  
  929.     CRLF        display a carriage return and a linefeed
  930.                 BV,DV,MV,CG,HG
  931.  
  932.     CLEOLN      clear from the cursor to the end of the line
  933.                 BV,DV,MV,CG,HG
  934.  
  935.     DELCHR      delete the character at the cursor
  936.                 MV
  937.  
  938.     DELLINE     delete the current line
  939.                 BV,dv,MV
  940.  
  941.     GETCOLOR    get the text color
  942.                 BV,MV,CG,HG
  943.                    -------
  944.                    AL = color/attribute
  945.  
  946.                         Video Services                  page 23
  947.  
  948.  
  949.  
  950.     GETMODE     get the current screen mode
  951.                 BV,MV
  952.                    -------
  953.                    AL = mode
  954.  
  955.     FIXCOLOR    whether to convert colors to monochrome
  956.                 BV,DV,MV
  957.                    AL <-- whether to convert (0 no, 1 yes)
  958.  
  959.     FRAME       display a window frame
  960.                 MV
  961.                    CH,CL <-- upper left corner (row, column)
  962.                    DH,DL <-- lower right corner (row, column)
  963.                    DS:SI <-- frame char list (-1 to -9 special)
  964.  
  965.     HIDECURSOR  hide the cursor
  966.                 BV,MV
  967.  
  968.     INIT        initialize the video service routines
  969.                 MV,CG
  970.  
  971.     INSCHR      insert a space at the cursor
  972.                 MV
  973.  
  974.     INSLINE     insert a row at the current line
  975.                 BV,dv,MV
  976.  
  977.     LOCATE      set the cursor position
  978.                 BV,DV,MV,CG,HG
  979.                    DH <-- row (1-25/43)
  980.                    DL <-- column (1-40/80/90)
  981.  
  982.     MODE        set the screen mode
  983.                 BV,DV,MV,CG,HG
  984.                    AL <-- mode (see General Video Info)
  985.  
  986.     POPUP       display a pop-up window
  987.                 BV,MV
  988.                    DS:DX <-- parameter pointer
  989.  
  990.     SAVESIZE    calculate bytes needed to save a screen area
  991.                 MV
  992.                    -------
  993.                    AL = bytes
  994.  
  995.                         Video Services                  page 24
  996.  
  997.  
  998.  
  999.     SCRREST     restore a saved screen area from a buffer
  1000.                 MV
  1001.                    DS:SI <-- buffer pointer
  1002.                    DH,DL <-- upper left corner (row, column)
  1003.  
  1004.     SCRSAVE     save a screen area into a buffer
  1005.                 MV
  1006.                    ES:DI <-- buffer pointer
  1007.                    CH,CL <-- upper left corner (row, column)
  1008.                    DH,DL <-- lower right corner (row, column)
  1009.                    -------
  1010.                       AX = bytes used to save screen area
  1011.  
  1012.     SHOWCURSOR  show the cursor
  1013.                 BV,MV
  1014.  
  1015.     STROUT      display a string
  1016.                 BV,DV,MV,CG,HG
  1017.                    DS:DX <-- pointer to ASCIIZ string
  1018.  
  1019.     WHERE       get the current cursor position
  1020.                 BV,MV,CG,HG
  1021.                    DH <-- row (1-25/43)
  1022.                    DL <-- column (1-40/80/90)
  1023.  
  1024.                         Video Services                  page 25
  1025.  
  1026.  
  1027.  
  1028. The ability to display graphics was once limited and very
  1029. expensive, but this is no longer true. PC-class computers have a
  1030. wide variety of graphics standards to choose from. This is
  1031. useful whether you are interested in games, business charts,
  1032. computer-aided design, icon-based mouse interfaces, or any
  1033. number of other applications. The AsmWiz library provides
  1034. numerous sets of graphics services which allow easy access to
  1035. the capabilities of whatever display is installed.
  1036.  
  1037. The graphics services are divided into sets of routines, with
  1038. each set of routines handling a specific video mode or modes.
  1039. This makes it possible to support just the modes you want,
  1040. without extraneous code being linked in.
  1041.  
  1042. All graphics services are machine-level and demand hardware
  1043. compatibility of both your computer and video adapter. This is
  1044. necessary because DOS doesn't support graphics at all, and the
  1045. BIOS only supports very slow single-pixel handling. If you are
  1046. able to run standard graphics programs on your computer,
  1047. however, you should experience no problems with these services.
  1048.  
  1049. All of the graphics services share a common nomenclature and
  1050. calling procedure. The video mode is specified as a two-letter
  1051. code prefix to the routine name, where the codes are as follows:
  1052.  
  1053.    Prefix     Mode(s)     Adapter     Resolution(s)     Colors
  1054.    ------    --------     -------    ----------------   ------
  1055.      G13        13h         VGA           320x200         256
  1056.      G4        4, 5         CGA           320x200           4
  1057.      G6          6          CGA           640x200           2
  1058.      GD         0Dh         EGA           320x200          16
  1059.      GE         0Eh         EGA           640x200          16
  1060.      GE         10h         EGA           640x350          16
  1061.      GE         11h         VGA           640x480           2
  1062.      GE         12h         VGA           640x480          16
  1063.      GH      Hercules       HGA           720x348           2
  1064.  
  1065. The service to display a line in Mode 6, for example, is named
  1066. G6_LINE.  Note that GE_ covers most EGA and VGA modes.
  1067.  
  1068.                         Video Services                  page 26
  1069.  
  1070.  
  1071.  
  1072. The following graphics services are available:
  1073.  
  1074.  
  1075.     BOX         draw a box
  1076.                 GH,G4,G6,GD,GE,G13
  1077.                    CX <-- left X coordinate
  1078.                    DX <-- top Y coordinate
  1079.                    SI <-- right X coordinate
  1080.                    DI <-- bottom Y coordinate
  1081.                    AH <-- whether to fill box (0 no, 1 yes)
  1082.                    AL <-- color
  1083.  
  1084.     GETPEL      get the current color of a point
  1085.                 GH,G4,G6,G13
  1086.                    CX <-- X coordinate
  1087.                    DX <-- Y coordinate
  1088.                    -------
  1089.                    AL = color
  1090.  
  1091.     LINE        draw a line
  1092.                 GH,G4,G6,GD,GE,G13
  1093.                    CX <-- left X coordinate
  1094.                    DX <-- top Y coordinate
  1095.                    SI <-- right X coordinate
  1096.                    DI <-- bottom Y coordinate
  1097.                    AL <-- color
  1098.  
  1099.     PLOT        plot a point
  1100.                 GH,G4,G6,GD,GE,G13
  1101.                    CX <-- X coordinate
  1102.                    DX <-- Y coordinate
  1103.                    AL <-- color
  1104.  
  1105.                     Miscellaneous Services              page 27
  1106.  
  1107.  
  1108.  
  1109. The Miscellaneous Services provide a number of services for
  1110. various purposes, such as parsing the command line, determining
  1111. the active video adapter, scanning the environment for a
  1112. parameter, and generating pseudo-random numbers. They eliminate
  1113. much of the tedium of these common chores.
  1114.  
  1115.  
  1116. The following services are available:
  1117.  
  1118.    MI_BOOT       reboot the computer (warm boot)
  1119.  
  1120.    MI_GETSCREEN  see what type of display is active
  1121.                     -------
  1122.                        AH = adapter type (1-6:
  1123.                                MDA, Herc, CGA, EGA, MCGA, VGA)
  1124.                        AL = color flag (0 color, 1 mono)
  1125.  
  1126.    MI_PARSE      parse a command line into filespecs & options
  1127.                     DS:SI <-- ptr to command line
  1128.                                  (for COM files, = CS:0080h)
  1129.                     ES:DI <-- ptr to filename buffer (128b)
  1130.                     ES:BX <-- ptr to option buffer (128 bytes)
  1131.                        AL <-- switch character (normally "/")
  1132.                     -------
  1133.                        AH = number of options
  1134.                        AL = number of filenames
  1135.  
  1136.    MI_RANDOM     generate a pseudo-random number
  1137.                        DX <-- random number range (1-4000)
  1138.                     -------
  1139.                        AX = random number (0 to DX - 1)
  1140.  
  1141.    MI_RANDOMIZE  initialize the pseudo-random number generator
  1142.                        AX <-- random number seed
  1143.                                  (use 0FFFFh for auto-seeding)
  1144.  
  1145.    MI_SCANENV    scan the DOS environment for a parameter
  1146.                     DS:SI <-- ptr to the DOS environment
  1147.                                  or similar table
  1148.                     ES:DI <-- ptr to the parm to search for
  1149.                     -------
  1150.                        CY if not found
  1151.                        NC if match found
  1152.                           if NC, DS:SI points to parm value
  1153.  
  1154.                          Error Codes                    page 28
  1155.  
  1156.  
  1157.  
  1158. DOS error codes are returned by various of the DOS services,
  1159. particularly the file and disk services. The code is returned in
  1160. the AL register. This is a list of some of the possible errors.
  1161.  
  1162.  
  1163.       2      file not found
  1164.       3      path not found
  1165.       4      too many open files (no handle available)
  1166.       5      access denied
  1167.       6      invalid handle
  1168.       8      insufficient memory
  1169.      15      invalid drive specified
  1170.      16      tried to remove current directory
  1171.      18      no more files
  1172.  
  1173.  
  1174.  
  1175.  
  1176. Critical error codes are returned by the EH_CRITERR service in
  1177. the AH register. This is a list of the possible errors.
  1178.  
  1179.  
  1180.       0      no critical error (if CY, it was a DOS error)
  1181.       1      write-protected disk
  1182.       2      unknown unit
  1183.       3      drive not ready
  1184.       4      unknown command
  1185.       5      data/CRC error
  1186.       6      bad request structure length
  1187.       7      seek error
  1188.       8      unknown media type
  1189.       9      sector not found
  1190.      10      printer out of paper
  1191.      11      write fault
  1192.      12      read fault
  1193.      13      general failure
  1194.      16      invalid disk change (only used by DOS 3+)
  1195.  
  1196.